package com.cn.controllor;

import com.cn.dao.UserDao;
import com.cn.dao.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "DeleteServlet")
public class DeleteServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserDao ud = new UserDaoImpl();
        int id;
        id=Integer.parseInt(request.getParameter("id"));
        if (ud.delete(id)){
            request.setAttribute("id","id");
            request.getRequestDispatcher("operationSuccess.jsp").forward(request,response);
        }else{
            response.sendRedirect("error,jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doPost(request,response);
    }
}
